/**
* Rule
* A rule object that will hold any information
* pertaining to the evaluation of a nonterminal
* of a language
*/
public class Rule{

	String head; // The name of the rule
	String tail; // Desired evaluation of the rule
 	String first; // given an input, the first for that input for the rule

	/**
	* Empty Constructor sets all variables to blank strings
	*/
	public Rule(){
		this.head="";
		this.tail="";
		this.first="";
	}
	
	/**
	* Constructor
	* given a line of input extracts global variables
	*
	* format: <head> : t1 t2 t3 | t4 t5
	* 		where t1-t5 are tokens or nonterminals and | delimits a new rule with the same head
	*
	* @param line a line of a text file
	*/
	public Rule(String line){
		this.head=getHead(line);
		this.tail=getTail(line);
	}
	
	/**
	* Prints the information of the rule
	*/
	public void print(){
		System.out.println(this);
	}
	
	public String toString(){
		return "Head: "+head+", Tail: "+tail+", First: "+first+".";
	}
	
	/**
	* Given a text line getHead will extract only the name of the rule
	* @param line the rule in text form
	* @return the name of the rule
	*/
	public String getHead(String line){
		String title =line.split("[:]+")[0];
		return title;
	}
		
	/**
	* Given a text line getTail will extract only the instructions for the rule
	* @param line the rule in text form
	* @return the instructions for the rule
	*/
	public String getTail(String line){
		String body=line.split("[:]+")[1];
		return body;
	}
	
	/**
	* Getters and setters
	*/
	
	public String getHead(){
		return head;
	}
	
	public void setHead(String head){
		this.head=head;
	}
	
	public String getTail(){
		return tail;
	}
	
	public void setTail(String tail){
		this.tail=tail;
	}
}
	
	